//生产

const {merge} = require('webpack-merge');
const common = require('./webpack.common.js');
const {CleanWebpackPlugin} = require('clean-webpack-plugin'); // 引入CleanWebpackPlugin插件
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlCriticalWebpackPlugin = require('html-critical-webpack-plugin'); // 集成critical的html-webpack-plugin版本
const path = require('path');

module.exports = merge(common, { // 将webpack.common.js合并到当前文件
    mode:'production',
    devtool: 'source-map',  // 会生成对于调试的完整的.map文件，但同时也会减慢打包速度
    plugins: [
        // new CleanWebpackPlugin(),  // 所要清理的文件夹名称
        new CopyWebpackPlugin(
            [{
                from: './src/font',
                to: './font',
            }]
        ),
        new HtmlCriticalWebpackPlugin({
            base: path.resolve(__dirname, '../dist'),
            src: 'index.html',
            dest: 'index.html',
            inline: true,
            minify: true,
            extract: true,
            width: 375,
            height: 565,
            // 确保调用打包后的JS文件
            penthouse: {
                blockJSRequests: false
            }
        }),


    ]
})